const KoaRouter = require('koa-router');
const HttpClient = require('../util/HttpClient');
const Template = require('../util/Template');

const router = new KoaRouter();
const modules = require('../../modules');

// 连接器列表
router.get('/connector/list', async ctx => {
  
  let script = ['/connector.list.js'];
  let modConfig = modules['connector.list'];
  let reqHeaders = ctx.request.headers;
  
  let result = await HttpClient.request('/connector/list', 'get', null, {
    headers: reqHeaders,
  });
  
  let body = result.body;
  
  ctx.body = await Template.renderWithHtml(
    '连接器列表',
    body,
    script,
    modConfig.template,
    ctx
  );
  
});

// 连接器列表
router.get('/connector/setting', async ctx => {
  
  let script = ['/connector.setting.js'];
  let modConfig = modules['connector.setting'];
  let reqHeaders = ctx.request.headers;
  
  let result = await HttpClient.request('/connector/setting', 'get', null, {
    headers: reqHeaders,
  });
  
  let body = result.body;
  
  ctx.body = await Template.renderWithHtml(
    '连接器设置',
    body,
    script,
    modConfig.template,
    ctx
  );
  
});

module.exports = router;
